home *** CD-ROM | disk | FTP | other *** search
- //////////////////////////////////////////////////////////////////////////////
- // CDPlay.cpp
- //
- // ©1995 SynthoWare
- // Simple CD Audio Player that doesn't display track/disk time
- //
- // Programmed By: Deryk B Robosson
- // E-mail: newlook@free.org
- // Snail-mail: 32609 Manistee
- // Westland, MI 48186
- // +1.313.990.3599
- //
- // Used: * AFrame
- // - Amiga C++ OOP Programmers Enhancements
- // - By Jeffry A Worth
- // - e-Mail: worth@emuvax.emich.edu
- // 73410.1112@compuserve.com
- // - And Deryk B Robosson
- // - See above for bug reports etc.
- //
- // * CDPlayer.library v37.0 on 29.5.1995
- // - By Patrick Hess
- // - e-Mail: poseidon@newswire.gun.de
- // poseidon@canta.gun.de
- // - SMail: Patrick Hess
- // Holsteinstr. 27
- // 41564 Kaarst
- // V+49-2131-6695556Q
- //////////////////////////////////////////////////////////////////////////////
-
- //////////////////////////////////////////////////////////////////////////////
- // Includes
- #include <exec/types.h>
- #include "aframe:cdplay/cdplay.hpp"
- #include <stdio.h>
- #include <string.h>
- #include <dos/dos.h>
- #include <libraries/cdplayer.h>
- #include <proto/cdplayer.h>
- #include <proto/dos.h>
- #include <proto/exec.h>
- #include <pragmas/cdplayer_pragmas.h>
- #include "aframe:include/amigaapp.hpp"
- #include "aframe:include/window.hpp"
- #include "aframe:include/rastport.hpp"
- #include "aframe:include/rect.hpp"
- #include "aframe:include/panel.hpp"
- #include "aframe:include/imagebutton.hpp"
- #include "aframe:cdplay/resources/Brushes_Select.res"
- #include "aframe:cdplay/resources/Brushes_Render.res"
- #include "aframe:cdplay/resources/About.res"
-
- ///////////////////////////////////////////////////////////////////////////////
- // GLOBAL VARS
- int CurTrack=1, paused=FALSE; // Always keep track of current track and paused status
- int result; // Keep a variable for return codes
- ULONG i=0, unit=2; // Default unit number change as necessary
- char text[40]="";
-
- // Misc required structs for us to use
- struct IOStdReq *CD_Request;
- struct MsgPort *CD_Port;
- struct Library *CDPlayerBase = NULL;
- struct CD_TOC table;
- struct CD_Time cd_time;
- struct CD_Volume vol;
- struct CD_Info info;
-
- ///////////////////////////////////////////////////////////////////////////////
- // About Window Class Definition
- // We have to tell the user about us a little bit don't we? ;)
-
- class AboutWindow: public AFWindow
- {
- public:
-
- virtual void OnCreate();
- virtual void OnGadgetUp(LPIntuiMessage imess);
- virtual void OnCloseWindow(LPIntuiMessage imess);
- virtual void DestroyWindow();
-
- AFPanel AboutPanel; // One panel for button
- AFPanel info_panel; // One panel for Info
- AFImageButton AboutButton; // One button!
- };
-
- //////////////////////////////////////////////////////////////////////////////
- // ControlWindow Class Definition
- // Main window definitions for our primary input
-
- class ControlWindow: public AFWindow
- {
- public:
- virtual void OnCreate();
- virtual void OnGadgetUp(LPIntuiMessage imess);
- virtual void DestroyWindow();
- virtual ULONG WindowFlags();
-
- AFImageButton Next, Prev, Stop, Play, Pause, About; // Our many image buttons
- };
-
- //////////////////////////////////////////////////////////////////////////////
- // ControlWindow Implementation routines
- // What we do on an exit request from the user
-
- void ControlWindow::DestroyWindow()
- {
- if(CD_Request) CloseDevice((struct IORequest *) CD_Request); // Close the device
- if(CD_Request) DeleteIORequest(CD_Request); // Delete the IORequest struct memory
- if(CD_Port) DeleteMsgPort(CD_Port); // Delete the message port
- if(CDPlayerBase) CloseLibrary(CDPlayerBase); // Close the library file
-
- AFWindow::DestroyWindow(); // Destroy the window
- delete this; // Delete the object
- }
-
- // We override the OnCreate() function so we can do some extra things that it
- // doesn't do for us.
- void ControlWindow::OnCreate()
- {
- AFRastPort rp(this);
-
- if(!(CDPlayerBase=(struct Library*)OpenLibrary((UBYTE*)CDPLAYERNAME,(ULONG)CDPLAYERVERSION)))
- DestroyWindow();
-
- CD_Port=CreateMsgPort();
- CD_Request=(struct IOStdReq *) CreateIORequest(CD_Port,sizeof(struct IOStdReq));
- OpenDevice((UBYTE * )"scsi.device",(ULONG)unit,(struct IORequest *) CD_Request,NULL);
- CDReadTOC(&table,CD_Request);
- CDTitleTime(&cd_time,CD_Request);
- CDInfo(&info,CD_Request);
- }
- // We override the OnGadgetUP function so we can handle the messages accordingly
- void ControlWindow::OnGadgetUp(LPIntuiMessage imess)
- {
- AFRastPort rp(this);
- AFRect rect, aboutrect;
- AboutWindow *about;
-
- switch(((struct Gadget*)imess->IAddress)->GadgetID) {
- case ID_PLAY: // User pressed PLAY button
- CDPlay((UBYTE)CurTrack,table.cdc_NumTracks,CD_Request); // Play first track
- break;
- case ID_PAUSE: // User pressed PAUSE Button
- if(paused==TRUE) { // If we were paused
- paused=FALSE; // We aren't now!
- CDResume(TRUE,CD_Request); // Pause the player
- } else {
- paused=TRUE; // If we weren't paused, we are now!
- CDResume(FALSE,CD_Request); // UnPause the player
- }
-
- break;
- case ID_STOP: // User pressed STOP button
- CDStop(CD_Request); // Stop the player
- break;
-
- case ID_NEXT: // User pressed NEXT track button
- CurTrack++; // increase track number
-
- if(CurTrack>table.cdc_NumTracks) { // if we are beyond total number of tracks
- CurTrack=table.cdc_NumTracks; // set current track to last avail track
- } else {
- CDPlay((UBYTE)CurTrack,(UBYTE)table.cdc_NumTracks,CD_Request); // Otherwise, play CurTrack
- }
- break;
-
- case ID_PREV: // User Pressed PREV track button
- CurTrack--; // decrease track number
-
- if(CurTrack<1) { // if we are smaller than track 1
- CurTrack=1; // set current track to track 1
- } else {
- CDPlay((UBYTE)CurTrack,(UBYTE)table.cdc_NumTracks,CD_Request); // Otherwise, play CurTrack
- }
- break;
-
- case ID_ABOUT: //User wants to know about us yeah, yeah, yeah!
- aboutrect.SetRect(10,10,212,115);
- about=new AboutWindow;
- about->Create(m_papp,&aboutrect); // Create our new window and wait...
- break;
-
- default:
- AFWindow::OnGadgetUp(imess); // the message wasn't for us, return it to Intuition
- break;
- }
- }
-
- ULONG ControlWindow::WindowFlags() // Added WindowFlags
- {
- return (AFWindow::WindowFlags() | WFLG_GIMMEZEROZERO);
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // About Window Implementation routines
- //
- // Deryk Robosson
- // December 18,1995
- //
-
- void AboutWindow::OnCreate() // What we are doing when our AboutWindow
- { // is being Created
- AFRect rect;
-
- rect.SetRect(2,11,94,103); // Set up our panel because image buttons can't have
- // Borders on them...
- AboutPanel.Create("",this,&rect,ID_ABOUTPANEL,PANEL_BEVELUP);
-
- rect.SetRect(4,13,92,101); // Set up the main image button
- AboutButton.Create(this,&rect,ID_ABOUTBOX,&about_image,NULL);
-
- rect.SetRect(96,11,184,103); // Create a panel for our useless text to be place in
- info_panel.Create("General Info",this,&rect,ID_ABOUTPANEL,PANEL_BEVELUP);
-
- AFWindow::RefreshGadgets(); // Refresh the gadgetlist so we can see the things
- // we just did! :)
- }
-
- void AboutWindow::OnGadgetUp(LPIntuiMessage imess)
- {
- switch(((struct Gadget*)imess->IAddress)->GadgetID) {
-
- case ID_ABOUTPANEL: // Handle things when user presses any of the three buttons
- case ID_ABOUTBOX:
- AboutWindow::DestroyWindow();
- break;
- default:
- AFWindow::OnGadgetUp(imess); // Wasn't our message!?
- break;
- }
- }
-
- void AboutWindow::OnCloseWindow(LPIntuiMessage imess)
- {
- AboutWindow::DestroyWindow();
- }
-
- void AboutWindow::DestroyWindow()
- {
- AFWindow::DestroyWindow();
- delete this;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- // MAIN
-
- void main()
- {
- AFAmigaApp theApp;
- AFRect rect(10,10,178,60); // Size of our main window
- ControlWindow win;
-
- win.Create(&theApp,&rect,"CDPlay"); // Create our main window
-
- rect.SetRect(2,2,24,35); // Create Previous button
- win.Prev.Create(&win,&rect,ID_PREV,&prev_render_image,&prev_select_image);
-
- rect.SetRect(26,2,48,35); // Create Next button
- win.Next.Create(&win,&rect,ID_NEXT,&next_render_image,&next_select_image);
-
- rect.SetRect(50,2,72,35); // Create Stop button
- win.Stop.Create(&win,&rect,ID_STOP,&stop_render_image,&stop_select_image);
-
- rect.SetRect(74,2,96,35); // Create Play button
- win.Play.Create(&win,&rect,ID_PLAY,&play_render_image,&play_select_image);
-
- rect.SetRect(98,2,120,35); // Create Pause button
- win.Pause.Create(&win,&rect,ID_PAUSE,&pause_render_image,&pause_select_image);
-
- rect.SetRect(122,2,144,35); // Create About button
- win.About.Create(&win,&rect,ID_ABOUT,&about_render_image,&about_select_image);
-
- win.RefreshGadgets(); // Let's refresh so you can see our work!
-
- theApp.RunApp(); // run the app and forget about it, it'll
- // take care of itself! ;) (isn't C++ wonderful??)
- }
-